package com.lht.testDemo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-08-09
 */
public class Genericity<T> {

    private   Class<T> t;
    public static void main(String [] args){
        new Genericity<String>().init();
//        System.out.println(new Foo<String>().getTClass());
    }
    private void init(){
        Type type = getClass().getGenericSuperclass();
//        ParameterizedType ptype=(ParameterizedType)type;
//        Type[] types = ptype.getActualTypeArguments();
        T t = JSON.parseObject("{}",new TypeReference<T>(){});
        System.out.println(t.getClass().getSimpleName());
    }

}

class Foo<T>{
    public Class<T> getTClass()
    {
        Class<T> tClass = (Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        return tClass;
    }
}

